use :: libc;
extern "C" {
    pub type _IO_wide_data;
    pub type _IO_codecvt;
    pub type _IO_marker;
    fn fclose(__stream: *mut FILE) -> i32;
    fn fopen(_: *const i8, _: *const i8) -> *mut FILE;
    fn printf(_: *const i8, _: ...) -> i32;
    fn genann_init(inputs: i32, hidden_layers: i32, hidden: i32, outputs: i32) -> *mut genann;
    fn genann_read(in_0: *mut FILE) -> *mut genann;
    fn genann_randomize(ann: *mut genann);
    fn genann_copy(ann: *const genann) -> *mut genann;
    fn genann_free(ann: *mut genann);
    fn genann_run(ann: *const genann, inputs: *const f64) -> *const f64;
    fn genann_train(
        ann: *const genann,
        inputs: *const f64,
        desired_outputs: *const f64,
        learning_rate: f64,
    );
    fn genann_write(ann: *const genann, out: *mut FILE);
    fn genann_act_sigmoid(ann: *const genann, a: f64) -> f64;
    fn genann_act_sigmoid_cached(ann: *const genann, a: f64) -> f64;
    fn genann_act_threshold(ann: *const genann, a: f64) -> f64;
    fn fabs(_: f64) -> f64;
    fn clock() -> clock_t;
    fn srand(__seed: u32);
}
pub type size_t = u64;
pub type __off_t = i64;
pub type __off64_t = i64;
pub type __clock_t = i64;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct _IO_FILE {
    pub _flags: i32,
    pub _IO_read_ptr: *mut i8,
    pub _IO_read_end: *mut i8,
    pub _IO_read_base: *mut i8,
    pub _IO_write_base: *mut i8,
    pub _IO_write_ptr: *mut i8,
    pub _IO_write_end: *mut i8,
    pub _IO_buf_base: *mut i8,
    pub _IO_buf_end: *mut i8,
    pub _IO_save_base: *mut i8,
    pub _IO_backup_base: *mut i8,
    pub _IO_save_end: *mut i8,
    pub _markers: *mut _IO_marker,
    pub _chain: *mut _IO_FILE,
    pub _fileno: i32,
    pub _flags2: i32,
    pub _old_offset: __off_t,
    pub _cur_column: u16,
    pub _vtable_offset: i8,
    pub _shortbuf: [i8; 1],
    pub _lock: *mut libc::c_void,
    pub _offset: __off64_t,
    pub _codecvt: *mut _IO_codecvt,
    pub _wide_data: *mut _IO_wide_data,
    pub _freeres_list: *mut _IO_FILE,
    pub _freeres_buf: *mut libc::c_void,
    pub __pad5: size_t,
    pub _mode: i32,
    pub _unused2: [i8; 20],
}
pub type _IO_lock_t = ();
pub type FILE = _IO_FILE;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct genann {
    pub inputs: i32,
    pub hidden_layers: i32,
    pub hidden: i32,
    pub outputs: i32,
    pub activation_hidden: genann_actfun,
    pub activation_output: genann_actfun,
    pub total_weights: i32,
    pub total_neurons: i32,
    pub weight: *mut f64,
    pub output: *mut f64,
    pub delta: *mut f64,
}
pub type genann_actfun = Option<unsafe extern "C" fn(*const genann, f64) -> f64>;
pub type clock_t = __clock_t;
static mut lfails: i32 = 0 as i32;
static mut ltests: i32 = 0 as i32;
#[no_mangle]
pub extern "C" fn basic() {
    let mut ann: *mut genann = unsafe { genann_init(1 as i32, 0 as i32, 0 as i32, 1 as i32) };
    (unsafe { ltests += 1 });
    if (unsafe { (*ann).total_weights }) != 2 as i32 {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%d != %d)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                37 as i32,
                (*ann).total_weights,
                2 as i32,
            )
        });
    }
    let mut a: f64 = 0.;
    a = 0 as i32 as f64;
    (unsafe { *((*ann).weight).offset(0 as i32 as isize) = 0 as i32 as f64 });
    (unsafe { *((*ann).weight).offset(1 as i32 as isize) = 0 as i32 as f64 });
    (unsafe { ltests += 1 });
    if (unsafe { fabs(0.5f64 - *genann_run(ann, &mut a)) }) > 0.001f64 {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                44 as i32,
                0.5f64,
                *genann_run(ann, &mut a),
            )
        });
    }
    a = 1 as i32 as f64;
    (unsafe { ltests += 1 });
    if (unsafe { fabs(0.5f64 - *genann_run(ann, &mut a)) }) > 0.001f64 {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                47 as i32,
                0.5f64,
                *genann_run(ann, &mut a),
            )
        });
    }
    a = 11 as i32 as f64;
    (unsafe { ltests += 1 });
    if (unsafe { fabs(0.5f64 - *genann_run(ann, &mut a)) }) > 0.001f64 {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                50 as i32,
                0.5f64,
                *genann_run(ann, &mut a),
            )
        });
    }
    a = 1 as i32 as f64;
    (unsafe { *((*ann).weight).offset(0 as i32 as isize) = 1 as i32 as f64 });
    (unsafe { *((*ann).weight).offset(1 as i32 as isize) = 1 as i32 as f64 });
    (unsafe { ltests += 1 });
    if (unsafe { fabs(0.5f64 - *genann_run(ann, &mut a)) }) > 0.001f64 {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                55 as i32,
                0.5f64,
                *genann_run(ann, &mut a),
            )
        });
    }
    a = 10 as i32 as f64;
    (unsafe { *((*ann).weight).offset(0 as i32 as isize) = 1 as i32 as f64 });
    (unsafe { *((*ann).weight).offset(1 as i32 as isize) = 1 as i32 as f64 });
    (unsafe { ltests += 1 });
    if (unsafe { fabs(1.0f64 - *genann_run(ann, &mut a)) }) > 0.001f64 {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                60 as i32,
                1.0f64,
                *genann_run(ann, &mut a),
            )
        });
    }
    a = -(10 as i32) as f64;
    (unsafe { ltests += 1 });
    if (unsafe { fabs(0.0f64 - *genann_run(ann, &mut a)) }) > 0.001f64 {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                63 as i32,
                0.0f64,
                *genann_run(ann, &mut a),
            )
        });
    }
    (unsafe { genann_free(ann) });
}
#[no_mangle]
pub extern "C" fn xor() {
    let mut ann: *mut genann = unsafe { genann_init(2 as i32, 1 as i32, 2 as i32, 1 as i32) };
    (unsafe {
        (*ann).activation_hidden =
            Some(genann_act_threshold as unsafe extern "C" fn(*const genann, f64) -> f64)
    });
    (unsafe {
        (*ann).activation_output =
            Some(genann_act_threshold as unsafe extern "C" fn(*const genann, f64) -> f64)
    });
    (unsafe { ltests += 1 });
    if (unsafe { (*ann).total_weights }) != 9 as i32 {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%d != %d)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                74 as i32,
                (*ann).total_weights,
                9 as i32,
            )
        });
    }
    (unsafe { *((*ann).weight).offset(0 as i32 as isize) = 0.5f64 });
    (unsafe { *((*ann).weight).offset(1 as i32 as isize) = 1 as i32 as f64 });
    (unsafe { *((*ann).weight).offset(2 as i32 as isize) = 1 as i32 as f64 });
    (unsafe { *((*ann).weight).offset(3 as i32 as isize) = 1 as i32 as f64 });
    (unsafe { *((*ann).weight).offset(4 as i32 as isize) = 1 as i32 as f64 });
    (unsafe { *((*ann).weight).offset(5 as i32 as isize) = 1 as i32 as f64 });
    (unsafe { *((*ann).weight).offset(6 as i32 as isize) = 0.5f64 });
    (unsafe { *((*ann).weight).offset(7 as i32 as isize) = 1 as i32 as f64 });
    (unsafe { *((*ann).weight).offset(8 as i32 as isize) = -(1 as i32) as f64 });
    let mut input: [[f64; 2]; 4] = [
        [0 as i32 as f64, 0 as i32 as f64],
        [0 as i32 as f64, 1 as i32 as f64],
        [1 as i32 as f64, 0 as i32 as f64],
        [1 as i32 as f64, 1 as i32 as f64],
    ];
    let mut output: [f64; 4] = [
        0 as i32 as f64,
        1 as i32 as f64,
        1 as i32 as f64,
        0 as i32 as f64,
    ];
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[0 as i32 as usize] - *genann_run(ann, (input[0 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                95 as i32,
                output[0 as i32 as usize],
                *genann_run(ann, (input[0 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[1 as i32 as usize] - *genann_run(ann, (input[1 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                96 as i32,
                output[1 as i32 as usize],
                *genann_run(ann, (input[1 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[2 as i32 as usize] - *genann_run(ann, (input[2 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                97 as i32,
                output[2 as i32 as usize],
                *genann_run(ann, (input[2 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[3 as i32 as usize] - *genann_run(ann, (input[3 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                98 as i32,
                output[3 as i32 as usize],
                *genann_run(ann, (input[3 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { genann_free(ann) });
}
#[no_mangle]
pub extern "C" fn backprop() {
    let mut ann: *mut genann = unsafe { genann_init(1 as i32, 0 as i32, 0 as i32, 1 as i32) };
    let mut input: f64 = 0.;
    let mut output: f64 = 0.;
    input = 0.5f64;
    output = 1 as i32 as f64;
    let mut first_try: f64 = unsafe { *genann_run(ann, &mut input) };
    (unsafe { genann_train(ann, &mut input, &mut output, 0.5f64) });
    let mut second_try: f64 = unsafe { *genann_run(ann, &mut input) };
    (unsafe { ltests += 1 });
    if !((unsafe { fabs(first_try - output) }) > (unsafe { fabs(second_try - output) })) {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d error \n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                114 as i32,
            )
        });
    }
    (unsafe { genann_free(ann) });
}
#[no_mangle]
pub extern "C" fn train_and() {
    let mut input: [[f64; 2]; 4] = [
        [0 as i32 as f64, 0 as i32 as f64],
        [0 as i32 as f64, 1 as i32 as f64],
        [1 as i32 as f64, 0 as i32 as f64],
        [1 as i32 as f64, 1 as i32 as f64],
    ];
    let mut output: [f64; 4] = [
        0 as i32 as f64,
        0 as i32 as f64,
        0 as i32 as f64,
        1 as i32 as f64,
    ];
    let mut ann: *mut genann = unsafe { genann_init(2 as i32, 0 as i32, 0 as i32, 1 as i32) };
    let mut i: i32 = 0;
    let mut j: i32 = 0;
    i = 0 as i32;
    while i < 50 as i32 {
        j = 0 as i32;
        while j < 4 as i32 {
            (unsafe {
                genann_train(
                    ann,
                    (input[j as usize]).as_mut_ptr(),
                    output.as_mut_ptr().offset(j as isize),
                    0.8f64,
                )
            });
            j += 1;
        }
        i += 1;
    }
    (unsafe {
        (*ann).activation_output =
            Some(genann_act_threshold as unsafe extern "C" fn(*const genann, f64) -> f64)
    });
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[0 as i32 as usize] - *genann_run(ann, (input[0 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                135 as i32,
                output[0 as i32 as usize],
                *genann_run(ann, (input[0 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[1 as i32 as usize] - *genann_run(ann, (input[1 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                136 as i32,
                output[1 as i32 as usize],
                *genann_run(ann, (input[1 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[2 as i32 as usize] - *genann_run(ann, (input[2 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                137 as i32,
                output[2 as i32 as usize],
                *genann_run(ann, (input[2 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[3 as i32 as usize] - *genann_run(ann, (input[3 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                138 as i32,
                output[3 as i32 as usize],
                *genann_run(ann, (input[3 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { genann_free(ann) });
}
#[no_mangle]
pub extern "C" fn train_or() {
    let mut input: [[f64; 2]; 4] = [
        [0 as i32 as f64, 0 as i32 as f64],
        [0 as i32 as f64, 1 as i32 as f64],
        [1 as i32 as f64, 0 as i32 as f64],
        [1 as i32 as f64, 1 as i32 as f64],
    ];
    let mut output: [f64; 4] = [
        0 as i32 as f64,
        1 as i32 as f64,
        1 as i32 as f64,
        1 as i32 as f64,
    ];
    let mut ann: *mut genann = unsafe { genann_init(2 as i32, 0 as i32, 0 as i32, 1 as i32) };
    (unsafe { genann_randomize(ann) });
    let mut i: i32 = 0;
    let mut j: i32 = 0;
    i = 0 as i32;
    while i < 50 as i32 {
        j = 0 as i32;
        while j < 4 as i32 {
            (unsafe {
                genann_train(
                    ann,
                    (input[j as usize]).as_mut_ptr(),
                    output.as_mut_ptr().offset(j as isize),
                    0.8f64,
                )
            });
            j += 1;
        }
        i += 1;
    }
    (unsafe {
        (*ann).activation_output =
            Some(genann_act_threshold as unsafe extern "C" fn(*const genann, f64) -> f64)
    });
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[0 as i32 as usize] - *genann_run(ann, (input[0 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                160 as i32,
                output[0 as i32 as usize],
                *genann_run(ann, (input[0 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[1 as i32 as usize] - *genann_run(ann, (input[1 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                161 as i32,
                output[1 as i32 as usize],
                *genann_run(ann, (input[1 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[2 as i32 as usize] - *genann_run(ann, (input[2 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                162 as i32,
                output[2 as i32 as usize],
                *genann_run(ann, (input[2 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[3 as i32 as usize] - *genann_run(ann, (input[3 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                163 as i32,
                output[3 as i32 as usize],
                *genann_run(ann, (input[3 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { genann_free(ann) });
}
#[no_mangle]
pub extern "C" fn train_xor() {
    let mut input: [[f64; 2]; 4] = [
        [0 as i32 as f64, 0 as i32 as f64],
        [0 as i32 as f64, 1 as i32 as f64],
        [1 as i32 as f64, 0 as i32 as f64],
        [1 as i32 as f64, 1 as i32 as f64],
    ];
    let mut output: [f64; 4] = [
        0 as i32 as f64,
        1 as i32 as f64,
        1 as i32 as f64,
        0 as i32 as f64,
    ];
    let mut ann: *mut genann = unsafe { genann_init(2 as i32, 1 as i32, 2 as i32, 1 as i32) };
    let mut i: i32 = 0;
    let mut j: i32 = 0;
    i = 0 as i32;
    while i < 500 as i32 {
        j = 0 as i32;
        while j < 4 as i32 {
            (unsafe {
                genann_train(
                    ann,
                    (input[j as usize]).as_mut_ptr(),
                    output.as_mut_ptr().offset(j as isize),
                    3 as i32 as f64,
                )
            });
            j += 1;
        }
        i += 1;
    }
    (unsafe {
        (*ann).activation_output =
            Some(genann_act_threshold as unsafe extern "C" fn(*const genann, f64) -> f64)
    });
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[0 as i32 as usize] - *genann_run(ann, (input[0 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                186 as i32,
                output[0 as i32 as usize],
                *genann_run(ann, (input[0 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[1 as i32 as usize] - *genann_run(ann, (input[1 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                187 as i32,
                output[1 as i32 as usize],
                *genann_run(ann, (input[1 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[2 as i32 as usize] - *genann_run(ann, (input[2 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                188 as i32,
                output[2 as i32 as usize],
                *genann_run(ann, (input[2 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe {
        fabs(output[3 as i32 as usize] - *genann_run(ann, (input[3 as i32 as usize]).as_mut_ptr()))
    }) > 0.001f64
    {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                189 as i32,
                output[3 as i32 as usize],
                *genann_run(ann, (input[3 as i32 as usize]).as_mut_ptr()),
            )
        });
    }
    (unsafe { genann_free(ann) });
}
#[no_mangle]
pub extern "C" fn persist() {
    let mut first: *mut genann =
        unsafe { genann_init(1000 as i32, 5 as i32, 50 as i32, 10 as i32) };
    let mut out: *mut FILE = unsafe {
        fopen(
            b"persist.txt\0" as *const u8 as *const i8,
            b"w\0" as *const u8 as *const i8,
        )
    };
    (unsafe { genann_write(first, out) });
    (unsafe { fclose(out) });
    let mut in_0: *mut FILE = unsafe {
        fopen(
            b"persist.txt\0" as *const u8 as *const i8,
            b"r\0" as *const u8 as *const i8,
        )
    };
    let mut second: *mut genann = unsafe { genann_read(in_0) };
    (unsafe { fclose(in_0) });
    (unsafe { ltests += 1 });
    if (unsafe { (*first).inputs }) != (unsafe { (*second).inputs }) {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%d != %d)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                208 as i32,
                (*first).inputs,
                (*second).inputs,
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe { (*first).hidden_layers }) != (unsafe { (*second).hidden_layers }) {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%d != %d)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                209 as i32,
                (*first).hidden_layers,
                (*second).hidden_layers,
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe { (*first).hidden }) != (unsafe { (*second).hidden }) {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%d != %d)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                210 as i32,
                (*first).hidden,
                (*second).hidden,
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe { (*first).outputs }) != (unsafe { (*second).outputs }) {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%d != %d)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                211 as i32,
                (*first).outputs,
                (*second).outputs,
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe { (*first).total_weights }) != (unsafe { (*second).total_weights }) {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%d != %d)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                212 as i32,
                (*first).total_weights,
                (*second).total_weights,
            )
        });
    }
    let mut i: i32 = 0;
    i = 0 as i32;
    while i < (unsafe { (*first).total_weights }) {
        (unsafe { ltests += 1 });
        if !((unsafe { *((*first).weight).offset(i as isize) })
            == (unsafe { *((*second).weight).offset(i as isize) }))
        {
            (unsafe { lfails += 1 });
            (unsafe {
                printf(
                    b"%s:%d error \n\0" as *const u8 as *const i8,
                    b"test.c\0" as *const u8 as *const i8,
                    216 as i32,
                )
            });
        }
        i += 1;
    }
    (unsafe { genann_free(first) });
    (unsafe { genann_free(second) });
}
#[no_mangle]
pub extern "C" fn copy() {
    let mut first: *mut genann =
        unsafe { genann_init(1000 as i32, 5 as i32, 50 as i32, 10 as i32) };
    let mut second: *mut genann = unsafe { genann_copy(first) };
    (unsafe { ltests += 1 });
    if (unsafe { (*first).inputs }) != (unsafe { (*second).inputs }) {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%d != %d)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                229 as i32,
                (*first).inputs,
                (*second).inputs,
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe { (*first).hidden_layers }) != (unsafe { (*second).hidden_layers }) {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%d != %d)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                230 as i32,
                (*first).hidden_layers,
                (*second).hidden_layers,
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe { (*first).hidden }) != (unsafe { (*second).hidden }) {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%d != %d)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                231 as i32,
                (*first).hidden,
                (*second).hidden,
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe { (*first).outputs }) != (unsafe { (*second).outputs }) {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%d != %d)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                232 as i32,
                (*first).outputs,
                (*second).outputs,
            )
        });
    }
    (unsafe { ltests += 1 });
    if (unsafe { (*first).total_weights }) != (unsafe { (*second).total_weights }) {
        (unsafe { lfails += 1 });
        (unsafe {
            printf(
                b"%s:%d (%d != %d)\n\0" as *const u8 as *const i8,
                b"test.c\0" as *const u8 as *const i8,
                233 as i32,
                (*first).total_weights,
                (*second).total_weights,
            )
        });
    }
    let mut i: i32 = 0;
    i = 0 as i32;
    while i < (unsafe { (*first).total_weights }) {
        (unsafe { ltests += 1 });
        if (unsafe {
            fabs(*((*first).weight).offset(i as isize) - *((*second).weight).offset(i as isize))
        }) > 0.001f64
        {
            (unsafe { lfails += 1 });
            (unsafe {
                printf(
                    b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                    b"test.c\0" as *const u8 as *const i8,
                    237 as i32,
                    *((*first).weight).offset(i as isize),
                    *((*second).weight).offset(i as isize),
                )
            });
        }
        i += 1;
    }
    (unsafe { genann_free(first) });
    (unsafe { genann_free(second) });
}
#[no_mangle]
pub extern "C" fn sigmoid() {
    let mut i: f64 = -(20 as i32) as f64;
    let max: f64 = 20 as i32 as f64;
    let d: f64 = 0.0001f64;
    while i < max {
        (unsafe { ltests += 1 });
        if (unsafe {
            fabs(
                genann_act_sigmoid(std::ptr::null::<genann>(), i)
                    - genann_act_sigmoid_cached(std::ptr::null::<genann>(), i),
            )
        }) > 0.001f64
        {
            (unsafe { lfails += 1 });
            (unsafe {
                printf(
                    b"%s:%d (%f != %f)\n\0" as *const u8 as *const i8,
                    b"test.c\0" as *const u8 as *const i8,
                    251 as i32,
                    genann_act_sigmoid(std::ptr::null::<genann>(), i),
                    genann_act_sigmoid_cached(std::ptr::null::<genann>(), i),
                )
            });
        }
        i += d;
    }
}
fn main_0(mut _argc: i32, mut _argv: *mut *mut i8) -> i32 {
    (unsafe { printf(b"GENANN TEST SUITE\n\0" as *const u8 as *const i8) });
    (unsafe { srand(100 as i32 as u32) });
    let ts: i32 = unsafe { ltests };
    let fs: i32 = unsafe { lfails };
    let start: clock_t = unsafe { clock() };
    (unsafe {
        printf(
            b"\t%-14s\0" as *const u8 as *const i8,
            b"basic\0" as *const u8 as *const i8,
        )
    });
    basic();
    (unsafe {
        printf(
            b"pass:%2d   fail:%2d   %4dms\n\0" as *const u8 as *const i8,
            ltests - ts - (lfails - fs),
            lfails - fs,
            ((clock() - start) * 1000 as i32 as i64 / 1000000 as i32 as __clock_t) as i32,
        )
    });
    let ts_0: i32 = unsafe { ltests };
    let fs_0: i32 = unsafe { lfails };
    let start_0: clock_t = unsafe { clock() };
    (unsafe {
        printf(
            b"\t%-14s\0" as *const u8 as *const i8,
            b"xor\0" as *const u8 as *const i8,
        )
    });
    xor();
    (unsafe {
        printf(
            b"pass:%2d   fail:%2d   %4dms\n\0" as *const u8 as *const i8,
            ltests - ts_0 - (lfails - fs_0),
            lfails - fs_0,
            ((clock() - start_0) * 1000 as i32 as i64 / 1000000 as i32 as __clock_t) as i32,
        )
    });
    let ts_1: i32 = unsafe { ltests };
    let fs_1: i32 = unsafe { lfails };
    let start_1: clock_t = unsafe { clock() };
    (unsafe {
        printf(
            b"\t%-14s\0" as *const u8 as *const i8,
            b"backprop\0" as *const u8 as *const i8,
        )
    });
    backprop();
    (unsafe {
        printf(
            b"pass:%2d   fail:%2d   %4dms\n\0" as *const u8 as *const i8,
            ltests - ts_1 - (lfails - fs_1),
            lfails - fs_1,
            ((clock() - start_1) * 1000 as i32 as i64 / 1000000 as i32 as __clock_t) as i32,
        )
    });
    let ts_2: i32 = unsafe { ltests };
    let fs_2: i32 = unsafe { lfails };
    let start_2: clock_t = unsafe { clock() };
    (unsafe {
        printf(
            b"\t%-14s\0" as *const u8 as *const i8,
            b"train and\0" as *const u8 as *const i8,
        )
    });
    train_and();
    (unsafe {
        printf(
            b"pass:%2d   fail:%2d   %4dms\n\0" as *const u8 as *const i8,
            ltests - ts_2 - (lfails - fs_2),
            lfails - fs_2,
            ((clock() - start_2) * 1000 as i32 as i64 / 1000000 as i32 as __clock_t) as i32,
        )
    });
    let ts_3: i32 = unsafe { ltests };
    let fs_3: i32 = unsafe { lfails };
    let start_3: clock_t = unsafe { clock() };
    (unsafe {
        printf(
            b"\t%-14s\0" as *const u8 as *const i8,
            b"train or\0" as *const u8 as *const i8,
        )
    });
    train_or();
    (unsafe {
        printf(
            b"pass:%2d   fail:%2d   %4dms\n\0" as *const u8 as *const i8,
            ltests - ts_3 - (lfails - fs_3),
            lfails - fs_3,
            ((clock() - start_3) * 1000 as i32 as i64 / 1000000 as i32 as __clock_t) as i32,
        )
    });
    let ts_4: i32 = unsafe { ltests };
    let fs_4: i32 = unsafe { lfails };
    let start_4: clock_t = unsafe { clock() };
    (unsafe {
        printf(
            b"\t%-14s\0" as *const u8 as *const i8,
            b"train xor\0" as *const u8 as *const i8,
        )
    });
    train_xor();
    (unsafe {
        printf(
            b"pass:%2d   fail:%2d   %4dms\n\0" as *const u8 as *const i8,
            ltests - ts_4 - (lfails - fs_4),
            lfails - fs_4,
            ((clock() - start_4) * 1000 as i32 as i64 / 1000000 as i32 as __clock_t) as i32,
        )
    });
    let ts_5: i32 = unsafe { ltests };
    let fs_5: i32 = unsafe { lfails };
    let start_5: clock_t = unsafe { clock() };
    (unsafe {
        printf(
            b"\t%-14s\0" as *const u8 as *const i8,
            b"persist\0" as *const u8 as *const i8,
        )
    });
    persist();
    (unsafe {
        printf(
            b"pass:%2d   fail:%2d   %4dms\n\0" as *const u8 as *const i8,
            ltests - ts_5 - (lfails - fs_5),
            lfails - fs_5,
            ((clock() - start_5) * 1000 as i32 as i64 / 1000000 as i32 as __clock_t) as i32,
        )
    });
    let ts_6: i32 = unsafe { ltests };
    let fs_6: i32 = unsafe { lfails };
    let start_6: clock_t = unsafe { clock() };
    (unsafe {
        printf(
            b"\t%-14s\0" as *const u8 as *const i8,
            b"copy\0" as *const u8 as *const i8,
        )
    });
    copy();
    (unsafe {
        printf(
            b"pass:%2d   fail:%2d   %4dms\n\0" as *const u8 as *const i8,
            ltests - ts_6 - (lfails - fs_6),
            lfails - fs_6,
            ((clock() - start_6) * 1000 as i32 as i64 / 1000000 as i32 as __clock_t) as i32,
        )
    });
    let ts_7: i32 = unsafe { ltests };
    let fs_7: i32 = unsafe { lfails };
    let start_7: clock_t = unsafe { clock() };
    (unsafe {
        printf(
            b"\t%-14s\0" as *const u8 as *const i8,
            b"sigmoid\0" as *const u8 as *const i8,
        )
    });
    sigmoid();
    (unsafe {
        printf(
            b"pass:%2d   fail:%2d   %4dms\n\0" as *const u8 as *const i8,
            ltests - ts_7 - (lfails - fs_7),
            lfails - fs_7,
            ((clock() - start_7) * 1000 as i32 as i64 / 1000000 as i32 as __clock_t) as i32,
        )
    });
    if (unsafe { lfails }) == 0 as i32 {
        (unsafe {
            printf(
                b"ALL TESTS PASSED (%d/%d)\n\0" as *const u8 as *const i8,
                ltests,
                ltests,
            )
        });
    } else {
        (unsafe {
            printf(
                b"SOME TESTS FAILED (%d/%d)\n\0" as *const u8 as *const i8,
                ltests - lfails,
                ltests,
            )
        });
    }
    return ((unsafe { lfails }) != 0 as i32) as i32;
}
pub fn main() {
    let mut args: Vec<*mut i8> = Vec::new();
    for arg in ::std::env::args() {
        args.push(
            (::std::ffi::CString::new(arg))
                .expect("Failed to convert argument into CString.")
                .into_raw(),
        );
    }
    args.push(::core::ptr::null_mut());
    {
        ::std::process::exit(
            main_0((args.len() - 1) as i32, args.as_mut_ptr() as *mut *mut i8) as i32,
        )
    }
}
